package com.jiang.jixiang.ui;

import android.os.Bundle;

import com.jiang.jixiang.R;
import com.jiang.jixiang.api.ApiUrl;
import com.jiang.jixiang.databinding.ActivityContactBinding;
import com.jiang.jixiang.network.CommonalityModel;
import com.jiang.jixiang.network.NetWorkListener;
import com.jiang.jixiang.network.okHttpModel;
import com.ws.universal.tools.base.BaseActivity;
import com.ws.universal.tools.base.ManageActivity;
import com.ws.universal.tools.utils.ToastUtils;

import org.json.JSONObject;

/**
 * 联系方式
 */
public class ContactActivity extends BaseActivity implements NetWorkListener {
    private ActivityContactBinding binding;

    @Override
    protected void initCreate(Bundle savedInstanceState) {
        ManageActivity.putActivity(this.getClass().getSimpleName(), this);
        binding = ActivityContactBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
    }

    @Override
    protected void initView() {
        binding.inTitle.titleTextTv.setText(R.string.contact_title);
        binding.inTitle.titleLeftBtn.setOnClickListener(view -> {
            finish();
        });
        loadData();
    }

    private void loadData() {
        showProgressDialog(false);
        okHttpModel.post(ApiUrl.about_Api, null, ApiUrl.about_Api_ID, this);
    }

    @Override
    protected void FinishDesTroy() {
        ManageActivity.removeActivity(this.getClass().getSimpleName());
    }

    @Override
    public void onSucceed(JSONObject jsonData, int id, CommonalityModel commonality) {
        stopProgressDialog();
        JSONObject data = jsonData.optJSONObject("data");
        switch (id) {
            case ApiUrl.about_Api_ID:
                binding.tvTel.setText(data.optString("tel"));
                binding.tvEmail.setText(data.optString("email"));

                break;
        }
    }

    @Override
    public void onFail(JSONObject jsonData, int id, CommonalityModel commonality) {
        stopProgressDialog();
        ToastUtils.showShort(commonality.getMessage());
    }

    @Override
    public void onError(int id, Exception e) {
        stopProgressDialog();
        ToastUtils.showShort(e.getMessage());
    }
}
